package com.example.mobile2036061550406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTxt;
    private RadioGroup radGupCarType;
    private RadioButton radBtnMainSaloon;
    private RadioButton radBtnMainMvp;
    private RadioButton radBtnMainSuv;
    private RadioGroup radBtnMainLine;
    private RadioButton radBtnMainLine1;
    private RadioButton radBtnMainLine2;
    private RadioButton radBtnMainLine3;
    private RadioButton radBtnMainLine4;
    private Button btnMainCreate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radGupCarType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                Log.i("RadioButton",radioButton.getText().toString());
            }
        });
        radBtnMainLine.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int lineId) {
                RadioButton radioButton = findViewById(lineId);
                Log.i("RadioButton",radioButton.getText().toString());
            }
        });
        btnMainCreate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String msg = "";
                int carId=radGupCarType.getCheckedRadioButtonId();
                if (carId != -1){
                    msg=((RadioButton)findViewById(carId)).getText().toString();
                }else{
                    msg = "未选择车型";
                }
                int lineId=radBtnMainLine.getCheckedRadioButtonId();
                if (lineId != -1){
                    msg=((RadioButton)findViewById(lineId)).getText().toString();
                }else{
                    msg = "未选择生产线";
                }
                Log.i("点击按钮",msg);
            }
        });
    }

    private void initView() {
        tvMainTxt = findViewById(R.id.tv_main_txt);
        radGupCarType = findViewById(R.id.radGup_car_type);
        radBtnMainSaloon = findViewById(R.id.radBtn_main_saloon);
        radBtnMainMvp = findViewById(R.id.radBtn_main_mvp);
        radBtnMainSuv = findViewById(R.id.radBtn_main_suv);
        radBtnMainLine = findViewById(R.id.radBtn_main_line);
        radBtnMainLine1 = findViewById(R.id.radBtn_main_line1);
        radBtnMainLine2 = findViewById(R.id.radBtn_main_line2);
        radBtnMainLine3 = findViewById(R.id.radBtn_main_line3);
        radBtnMainLine4 = findViewById(R.id.radBtn_main_line4);
        btnMainCreate = findViewById(R.id.btn_main_create);
    }
}